<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="copyright" content="Tencent"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>
    	<c:choose>
    		<c:when test="${point == 2}">
    			设置姓名
    		</c:when>
    		<c:when test="${point == 3}">
    			设置职务
    		</c:when>
    		<c:when test="${point == 4}">
    			设置手机
    		</c:when>
    		<c:when test="${point == 5}">
    			设置座机
    		</c:when>
    		<c:when test="${point == 6}">
    			设置邮箱
    		</c:when>
    		<c:when test="${point == 7}">
    			设置微博
    		</c:when>
    		<c:when test="${point == 8}">
    			设置微信
    		</c:when>
    		<c:when test="${point == 9}">
    			设置QQ
    		</c:when>
    		<c:when test="${point == 10}">
    			设置座右铭
    		</c:when>
    	</c:choose>
    </title>
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/companycard/public.css" />
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/companycard/s04.css" />
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/companycard/s02.css" />
</head>
<body>   
    <div class="s_input_box">
    	<c:choose>
    		<c:when test="${point == 2}">
    			<input type="text" class="s_input" onblur="toModify()" id="J-xname" value="${bmcompanyCard.name }" />
    		</c:when>
    		<c:when test="${point == 3}">
    			<input type="text" class="s_input" onblur="toModify()" id="J-xjob" value="${bmcompanyCard.job }" />
    		</c:when>
    		<c:when test="${point == 4}">
    			<input type="text" class="s_input" onblur="toModify()" id="J-xmobile" value="${bmcompanyCard.mobile }" />
    		</c:when>
    		<c:when test="${point == 5}">
    			<input type="text" class="s_input" onblur="toModify()" id="J-xzuoMobile" value="${bmcompanyCard.telephone }" />
    		</c:when>
    		<c:when test="${point == 6}">
    			<input type="text" class="s_input" onblur="toModify()" id="J-xmail" value="${bmcompanyCard.mail }" />
    		</c:when>
    		<c:when test="${point == 7}">
    			<input type="text" class="s_input" onblur="toModify()" id="J-xweibo" value="${bmcompanyCard.weibo }" />
    		</c:when>
    		<c:when test="${point == 8}">
    			<input type="text" class="s_input" onblur="toModify()" id="J-xweixin" value="${bmcompanyCard.weixin }" />
    		</c:when>
    		<c:when test="${point == 9}">
    			<input type="text" class="s_input" onblur="toModify()" id="J-xqq" value="${bmcompanyCard.qq }" />
    		</c:when>
    		
    		<c:when test="${point == 10}">
    			<input type="text" class="s_input" onblur="toModify()" id="J-motto" value="${bmcompanyCard.motto }" />
    		</c:when>
    		
    	</c:choose>
        <span><img class="delICON" src="<%=path%>/images/companycard/delete.png" /></span>
    </div>
    <p class="hint">*点击屏幕任意位置保存！</p>
    <script type="text/javascript" src="<%=path%>/js/companycard/jquery-1.8.1.min.js"></script> 
    <script type="text/javascript">
        $('.delICON').on('click',function(){
            $('.s_input').val('');
        })
        function checkTel(obj){  
		   var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/;  
		   var isMob=/^1[34578]\d{9}$/;
		   if(isMob.test(obj)||isPhone.test(obj)){
		       return true;  
		   }  
		   else{  
		       return false;  
		   }  
		}  
        function toModify(){
        	var name = "${bmcompanyCard.name }";
        	var job = "${bmcompanyCard.job }";
        	var mobile = "${bmcompanyCard.mobile }";
        	var zuoMobile = "${bmcompanyCard.telephone }";
        	var mail = "${bmcompanyCard.mail }";
        	var weibo = "${bmcompanyCard.weibo }";
        	var weixin = "${bmcompanyCard.weixin }";
        	var qq = "${bmcompanyCard.qq }";
        	var motto = "${bmcompanyCard.motto }";
        	if(typeof($("#J-xname").val()) != "undefined"){
        		name = $("#J-xname").val();
        		if(name.trim() == ""){
            		alert("请输入姓名");
            		return;
            	}
        	}
        	if(typeof($("#J-xjob").val()) != "undefined"){
        		job = $("#J-xjob").val();
        		if(job.trim() == ""){
            		alert("请输入职务");
            		return;
            	}
        	}
        	if(typeof($("#J-xmobile").val()) != "undefined"){
        		mobile = $("#J-xmobile").val();
        		if(mobile.trim() == ""){
            		alert("请输入手机");
            		return;
            	}
        		if(!checkTel(mobile.trim())){
        			alert("手机号码有误，请重填");  
        	        return;
        		}
        	}
        	if(typeof($("#J-xzuoMobile").val()) != "undefined"){
        		zuoMobile = $("#J-xzuoMobile").val();
        		if(zuoMobile.trim() != ""){
        			if(!checkTel(zuoMobile.trim())){
            			alert("座机号码有误，请重填");  
            	        return;
            		}
        		}
        	}
        	if(typeof($("#J-xmail").val()) != "undefined"){
        		mail = $("#J-xmail").val();
        		var szReg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        		if(mail.trim() != ""){
        			if(!szReg.test(mail.trim())){
        				alert("邮箱有误，请重填");
        				return;
        			}
        		}
        	}
        	if(typeof($("#J-xweibo").val()) != "undefined"){
        		weibo = $("#J-xweibo").val();
        		var wbReg=/^[\u4e00-\u9fa5a-zA-Z0-9_-]{4,30}$/;
        		if(weibo.trim() != ""){
        			if(!wbReg.test(weibo.trim())){
        				alert("微博号有误，请重填");
        				return;
        			}
        		}
        	}
        	if(typeof($("#J-xweixin").val()) != "undefined"){
        		weixin = $("#J-xweixin").val();
        		var wxPattern = /^[\w-\s]+$/;
        		var wxno = 0;
        		if(weixin.trim() != ""){
        			if(wxPattern.test(weixin.trim())){
        				wxno = 1;
        			}
        		}
        		if(wxno != 1){
        			alert("微信号有误，请重填");
    				return;
        		}
        	}
        	if(typeof($("#J-xqq").val()) != "undefined"){
        		qq = $("#J-xqq").val();
        		var qqPattern = /^[1-9][0-9]{4,10}$/;
        		if(qq.trim() != ""){
        			if(!qqPattern.test(qq.trim())){
        				alert("qq号有误，请重填");
        				return;
        			}
        		}
        	}
        	if(typeof($("#J-motto").val()) != "undefined"){
        		motto = $("#J-motto").val();
        	} 
        	$.ajax({
       		  url: "<%=path%>/mobile/ajaxUpdateBusinessCardInfo",
       		  type: "post",		      	  
       		  async: false,
       		  data:{
       			  "id":"${bmcompanyCard.id}",
       			  "name":name,
       			  "job":job,
       			  "mobile":mobile,
       			  "telephone":zuoMobile,
       			  "mail":mail,
       			  "weibo":weibo,
       			  "weixin":weixin,
       			  "qq":qq , 
       		      "motto":motto 
       		  },
       		  dataType: "json",
       		  timeout: 1000,
       		  error: function(){},
       		  success: function(data){ 
       			  //console.log(data);
       			  /* data=JSON.parse(data); */
	         		  if (data.status=="200") {
	         			 window.location.href = "<%=path%>/mobile/pageUserInfoSetting"; 			 
	         		  }else if(data.error_code == "20028"){
	         			  alert("会话过期，请重新登录");
	         			  window.location.href = "<%=path%>/mobile/toLogin";
	         		  }else{
	         			 alert(data.error_message);
	         		  }
       		  }
       		});
        }
    </script>
</body>
</html>